import time
from typing import List, Dict

class MemoryItem:
    def __init__(self, text):
        self.text = text
        self.improtance:float = 0.0
        self.mention_count:int = 1
        self.last_mentioned:float = time.time()

    def updateImportance(self, keywords:List[str]):
        for keyword in keywords:
            if keyword in self.text:
                self.improtance += 1
    
    def updateMention(self):
        self.mention_count +=1
        self.last_mentioned = time.time()
    
    def toDict(self) ->Dict:
        return {
            "text":self.text,
            "importance":self.improtance,
            "mention_count":self.mention_count,
            "last_mentioned":self.last_mentioned
        }
    
    @staticmethod
    def fromDict(self, data:Dict) :
        item = MemoryItem(data["text"])
        item.improtance = data["importance"]
        item.mention_count = data["mention_count"]
        item.last_mentioned = data["last_mentioned"]
        return item
    
